package com.design03_behavioral.pattern13_observer.example03;

import com.design03_behavioral.pattern13_observer.example02.LotteryResult;

/**
 * @ClassName  开奖服务接口
 * @Description TODO
 * @Author zhangjunhao
 * @DATE 2023/9/6 22:37
 */
public abstract class LotteryService {

    private EventManager eventManager;
    protected abstract LotteryResult lottery(String uId);

    public LotteryService(){//子类会调用
        //设置事件类型
        eventManager = new EventManager(EventManager.EventType.MQ, EventManager.EventType.Message);
        eventManager.subscribe(EventManager.EventType.Message,new MessageEventListener());
        eventManager.subscribe(EventManager.EventType.MQ,new MQEventListener());

    }


    public LotteryResult lotteryAndMsg(String uId){
        LotteryResult result = lottery(uId);

        //发送通知
        eventManager.notify(EventManager.EventType.Message,result);
        eventManager.notify(EventManager.EventType.MQ,result);

        return result;

    }




}
